package com.sicurezza.nfcrypto;

import android.app.IntentService;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;

import com.sicurezza.db.KeyContactContract.KeyContactEntry;
import com.sicurezza.db.KeyContactDbHelper;

public class DbUpdater extends IntentService {

	public static final String CONTACT_ID = "CID";
	public static final String CONTACT_DISPLAY_NAME = "CDN";
	public static final String CONTACT_PHONE_NUMBER = "CPN";
	public static final String CONTACT_EMAIL_ADDRESS = "CEA";
	public static final String SALT_STRING_VALUE = "SSV";
	public static final String KEY_HASH_VALUE = "KHV";
	
	public DbUpdater() {
		super("DbUpdater");
	}

	@Override
	protected void onHandleIntent(Intent intent) {
		String contactID = intent.getStringExtra(CONTACT_ID), contactDisplayName = intent.getStringExtra(CONTACT_DISPLAY_NAME),
				contactPhoneNumber = intent.getStringExtra(CONTACT_PHONE_NUMBER), contactEmailAddress = intent.getStringExtra(CONTACT_EMAIL_ADDRESS),
				saltStringValue = intent.getStringExtra(SALT_STRING_VALUE), keyHashValue = intent.getStringExtra(KEY_HASH_VALUE);
		KeyContactDbHelper myDbHelper = new KeyContactDbHelper(this);
		SQLiteDatabase db = myDbHelper.getWritableDatabase();
		
		ContentValues values = new ContentValues();
		values.put(KeyContactEntry.CONTACT_ID, contactID);
		values.put(KeyContactEntry.CONTACT_DISPLAY_NAME, contactDisplayName);
		values.put(KeyContactEntry.CONTACT_PHONE_NUMBER, contactPhoneNumber);
		values.put(KeyContactEntry.CONTACT_EMAIL_ADDRESS, contactEmailAddress);
		values.put(KeyContactEntry.SALT_STRING_VALUE, saltStringValue);
		values.put(KeyContactEntry.KEY_HASH_VALUE, keyHashValue);
		
		db.insert(KeyContactEntry.TABLE_NAME, null, values);

	}

}
